Adding some more judges, here and there.
[and.git] / UVa / 11588 - Image coding / 11588.cpp
blob28f2364ce999ffa092d9ddfc5175e880837e62af
1 //AC
2 using namespace std;
3 #include <algorithm>
4 #include <iostream>
5 #include <iterator>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 template <class T> string toStr(const T &x){ stringstream s; s << x; return s.str(); }
24 template <class T> int toInt(const T &x){ stringstream s; s << x; int r; s >> r; return r; }
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define D(x) cout << #x " is " << x << endl
30 char mat[25][25];
32 int main(){
33 int casos;
34 cin >> casos;
35 for (int C=1; C<=casos; ++C){
36 cout << "Case " << C << ": ";
37 int rows, cols, important, notimportant;
38 cin >> rows >> cols >> important >> notimportant;
40 map<char, int> freq;
41 For(i, 0, rows){
42 For(j, 0, cols){
43 cin >> mat[i][j];
44 freq[mat[i][j]]++;
47 vector<pair<int, char> > v;
48 foreach(p, freq){
49 v.push_back(make_pair(p->second, p->first));
51 sort(v.rbegin(), v.rend());
52 int ans = 0;
53 for (int i=0; i<v.size(); ++i){
54 if (v[i].first == v[0].first) ans += v[i].first * important;
55 else ans += v[i].first * notimportant;
57 cout << ans << endl;
59 return 0;